<?php
ob_start();
define('ROOT_PATH', '/var/www/html/new/d');
include 'common/autoload.php';
include 'common/header.html';
include 'common/left.html';
include 'common/page.php';
include 'common/area.inc.php';
include 'common/Prod_Common.php';
$out_html=ob_get_contents();
ob_end_clean();
use \pft\Prod\Product;
use \pft\Member\MemberAccount;

$lvl_limit = array(0, 2, 6, 9);
if(!in_array($_SESSION['dtype'], $lvl_limit)) {
    exit('不合法的身份！');
}
if ($_SESSION['dtype']==6 && !strpos($_SESSION['qx'],'upProd')) {
    if(\pft\Member\MemberAccount::GetMemType($_SESSION['sid'])!=0) {
        exit('您的上级不是供应商身份，无法发布产品。');
    }
}
if(empty($_SESSION['com_type'])) {
    $sqlGetComType = "SELECT com_type FROM pft_member_extinfo WHERE fid={$_SESSION['sid']}";
    $GLOBALS['le']->query($sqlGetComType);
    $GLOBALS['le']->fetch_assoc();
    $_SESSION['com_type'] = $GLOBALS['le']->f('com_type');
}
$currentPage =$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize    =$_REQUEST["pageSize"]?$_REQUEST["pageSize"]:10;
$offset      =($currentPage-1)*$pageSize;
if(isset($_REQUEST['act']) && $_REQUEST['act']=="Export"){
	$offset=0;
    $pageSize=999999999;
}
if(!isset($status)) {
    $status = isset($_GET['s']) ? abs($_GET['s']) : 1;
}
$title_status = array(
    1 => '自供应产品',
    2 => '下架产品',
    3 => '待发布产品',
);
$page_title = $title_status[$status];

if(!is_numeric($status)) {
    exit('非法的参数！');
}


$ticketOption = array(
    'apply_limit'=> $status,
);
if($_SESSION['dtype']==0) {
    $params['applyer'] = $_SESSION['sid'];
}
elseif($_SESSION['dtype']==6 && $_SESSION['sid']!=1) {
    $params['applyer'] = $_SESSION['sid'];
}
elseif($_SESSION['dtype']==2) {
    $mem = new MemberAccount($GLOBALS['le']);
    $params['salerid'] = $mem->getAccountById($_SESSION['sid']);
}
if(!empty($_GET['s_input'])) {
    $p_title = trim(strip_tags($_GET['s_input']));
    $params['title'] = addslashes($p_title);
}

if (!empty($_GET['apply_did']) && $_SESSION['sdtype']==9) {
    $params['applyer'] = intval($_GET['apply_did']);
}
if (is_numeric($_GET['d_province']) && $_GET['d_province']>0) {
    $params['area'] = $_GET['d_province'] . '|';
    if (is_numeric($_GET['d_city']) && $_GET['d_city']>0) {
        $params['area'] .= $_GET['d_city'];
    }
}  

$params['status'] = $status;
$params['limit']  = $offset;
$params['offset'] = $pageSize;

if(!empty($_GET['s_title'])) {
    $params['title'] = safetxt($_GET['s_title']);
}
if(!empty($_GET['p_type']) && $_GET['p_type']) {
    $params['p_type'] = safetxt($_GET['p_type']);
}
if(ctype_digit($_GET['terminal'])) {
    $params['terminal'] = $_GET['terminal'];
}
if($_GET['supplier']){
    $params['supplier'] = $_GET['supplier'] + 0;
}
if($_GET['btime']){
    $params['bt'] = safetxt($_GET['btime']);
}
if($_GET['etime']){
    $params['et'] = safetxt($_GET['etime']);
}
$soap = SoapInit::GetSoapInside();
$obj = new Product($GLOBALS['le'], $soap);
$st=(($_SESSION['dtype']=="9") && safetxt($_GET['filter']));
$onlyland=(intval($_GET['only'])==1);
$data = $obj->GetProductsList($params, $ticketOption,$onlyland,$st);

//$ptype_count = array();



$add_list = array('A'=>'票类','B'=>'票类','C'=>'客房','D'=>'商品','F'=>'套票');
$sta_list = array('0'=>'<span class="red">[未审核]</span>','','<span class="red">[被拒绝]</span>');
$debug    = false;

//TODO::获取会员数据
$memberNames = include dirname(__FILE__) . '/module/link_product/Member.cache.php';
// 仓库中的产品
if($status==2) {
    // 加载套票系统下架提示
    $packageMsg = include '/var/www/html/new/d/module/link_product/tarMessage.php';
}

if ($_GET['cgp']) {
    echo "<pre>";
    print_r($data['lands']);
//    page($data['total'],$currentPage,$pageSize);

    exit;
}
//导览账号配置
$id_list = array(1433,4971,7508,94,1229,7517,20270);
// admin 账号
// if($_SESSION['sid']==1){
    // include 'getDistors.php';
    // $DistorsNames = getAllMember($GLOBALS['le'], 0);
// }
if(isset($_REQUEST['act']) && $_REQUEST['act']=="Export")
{   
	$filename=date('YmdHis').'分销商产品列表';
    $Excel[0]['a']='省';
    $Excel[0]['b']='市';
    $Excel[0]['c']='景区SID';
    $Excel[0]['d']='景区6位数ID';
    $Excel[0]['e']='景区名称';
    $Excel[0]['f']='供应商';
    $Excel[0]['g']='状态';
    $Excel[0]['h']='景区级别';
    $Excel[0]['i']='景区主题';
    $Excel[0]['j']='创建时间';
    $Excel[0]['k']='供货价';
    $Excel[0]['l']='门市价';
    $Excel[0]['m']='建议零售价';
    $Excel[0]['n']='取票信息';
	$i=2;
    foreach($data['lands'] as  $prod){
        list($q,$sort[]) = explode('|', $prod['area']);
    }
    array_multisort($sort,$data['lands']);//根据地区来排序
    if($_GET['only']==1){

        foreach($data['lands'] as $prod){
            list($prov, $city) = explode('|', $prod['area']);
            $Excel[$i]['a']=$areas[$prov];
            $Excel[$i]['b']=$areas[$city];
            $Excel[$i]['c']=$prod['id'];
            $Excel[$i]['d']=$prod['salerid'];
            $Excel[$i]['e']=$prod['title'];
            $Excel[$i]['f']=$memberNames[$prod['apply_did']];
            $Excel[$i]['g']=($status==1)? '在售':'仓库';
            $Excel[$i]['h']=$prod['jtype'];
            $Excel[$i]['i']=$prod['topic'];
            $Excel[$i]['j']=$prod['addtime'];
            $i++;
        }
    }else{
        foreach($data['lands'] as $prod){
            list($prov, $city) = explode('|', $prod['area']);
            if(count($data['tickets'][$prod['id']])){
                foreach($data['tickets'][$prod['id']] as $key => $ticket){
                    $Excel[$i]['a']=$areas[$prov];
                    $Excel[$i]['b']=$areas[$city];
                    $Excel[$i]['c']=$prod['id'];
                    $Excel[$i]['d']=$prod['salerid'];
                    $Excel[$i]['e']=$prod['title'].$ticket['title'];
                    $Excel[$i]['f']=$memberNames[$prod['apply_did']];
                    $Excel[$i]['g']=($status==1)? '在售':'仓库';
                    $Excel[$i]['h']=$prod['jtype'];
                    $Excel[$i]['i']=$prod['topic'];
                    $Excel[$i]['j']=$ticket['verify_time'];
                    $Excel[$i]['k']=$ticket['fprice'];
                    $Excel[$i]['l']=$ticket['uprice'];
                    $Excel[$i]['m']=$ticket['tprice'];
                    $Excel[$i]['n']=$ticket['getaddr'];
                    $i++;
                }
            }
        }
    }
	$xls = new SimpleExcel('UTF-8', true,'land');
    $xls->addArray($Excel);
    $xls->generateXML($filename);
	exit;
}
echo $out_html;

// 显示导览链接
$var['guides_f'] = false;
if($_SESSION['sid']==1433 || $_SESSION['sid']==4971 || $_SESSION['sid']==7508 || $_SESSION['sid']==1229 || $_SESSION['sid']==94 || $_SESSION['sid']==20270){
	$var['guides_f'] = true;
}

$var['can_more_package'] = false;
if($_SESSION['sid']==1433 || $_SESSION['sid']==4971 || $_SESSION['sid']==7508 ||$_SESSION['sid']==1229){
	$var['can_more_package'] = true;
} 

// if($_SESSION['sid']==1433){
	// print_r($data);
// }
//include TPLPATH.'prodlists_sync.tpl';
//$debug = $_GET["debug"];
/*if(!isset($debug)){
	include('tpl/prodlists_sync.tpl');
}else{*/
include('tpl/prodlists_today.tpl');

include 'common/footer.html';
?>